package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.AddActionEvent;
	import net.optix.ip.events.GetActionsEvent;
	import net.optix.ip.model.ModelLocator;
	
	public class AddActionCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:AddActionEvent = AddActionEvent( event );
			
			var delegate:InventionDelegate = new InventionDelegate();     
			delegate.addAction( this,myEvent.vo );
			
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			try
			{
				var	result:int				=	event.result.result;
				switch(result)
				{
					case -2:
						model.result	=	"Access Denied.";
						break;
					case 0:
						model.result	=	"Program error!";
						break;
					case 1:
						if(model.role == 1 || model.role == 2)
						{
							model.result	=	"Successfully add disclosure for the invention .";
						}
						else
						{
							model.result	=	"Your filing is recorded .";
						}						
						model.close		=	"no";
						model.close		=	"yes";
						
						var getActions:GetActionsEvent	=	new GetActionsEvent(model.currentInvention.inventionID);
						com.adobe.cairngorm.control.CairngormEventDispatcher.getInstance().dispatchEvent(getActions);
						break;
				}
			}
			catch(error:Error)
			{
				trace(error);
				model.result	=	"Program error";
			}
			
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			model.result	=	"Program error";	
			model.bSubmit	=	true;
		}

	}
}